<?php

namespace app\admin\model;

use app\admin\model\User as UserModel;
use app\common\model\Withdraw as BaseModel;

class Withdraw extends BaseModel
{


    /**
     * 搜索器 字段phone
     */
    public function searchPhoneAttr($query, $value){
        if ($value) {
            $userIds = UserModel::where('phone','like',$value.'%')->column('id');
            $userIds = $userIds?:[0];
            $query->where('user_id','in',$userIds);
        }
    }

	/**
     * 搜索器搜索订单号
     */
    public function searchOrderSnAttr($query,$value)
    {
        if ($value){
            $query->where('order_sn','like','%'.$value.'%');
        }
    }
	/**
     * 搜索器搜索状态
     */
    public function searchStatusAttr($query,$value)
    {
        if ($value!==''){
            $query->where('status',$value);
        }
    }


    public function searchBankNumberAttr($query, $value)
    {
        if ($value) {
            $query->json(['bank'])->where('bank->bank_number','like','%'.$value.'%');
        }
    }

    public function searchUserIdsAttr($query, $value)
    {
        if ($value) {
            $arr =  explode(',',$value);
            $query->where('user_id','in',$arr);
        }
    }
}